/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Importer.java
 *
 * Created on 9 Φεβ 2011, 11:43:25 πμ
 */
package importDb.base;

import models.Database;
import components.MyDraggable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import models.Receipt;
import models.Type;
import receipts.Main;
import tools.Helper;
import tools.options.Options;

/**
 *
 * @author ssoldatos
 */
public class Importer extends MyDraggable implements ImportConstants {

  private static final long serialVersionUID = 3424534535L;
  private ArrayList<String[]> data;
  private ArrayList<String[]> wrongData = new ArrayList<String[]>();
  private int[] fields;
  public boolean imported = false;
  private int thousandDel;
  private int decimalDel;
  private String database;
  private int multiDecimalDel;
  private int correct = 0;
  private int wrong = 0;

  /** Creates new form Importer */
  public Importer() {
  }

  Importer(String database, ArrayList<String[]> data, int[] fields,
      int thousandDel, int decimalDel, int multiDecimalDel) {
    this.data = data;
    this.database = database;
    this.fields = fields;
    this.thousandDel = thousandDel;
    this.decimalDel = decimalDel;
    this.multiDecimalDel = multiDecimalDel;
    Main.glassPane.activate(null);
    initComponents();
    lb_database.setText(database);
    lb_thousands.setText(THOUSAND_DEL[thousandDel]);
    lb_decimal.setText(DECIMAL_DEL[decimalDel]);
    lb_totals.setText(String.valueOf(data.size()));
    lb_multi.setText(MULTI_DEC_DEL[multiDecimalDel]);
    setLocationRelativeTo(null);
    setVisible(true);


  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel2 = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    progress = new javax.swing.JProgressBar();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    lb_database = new javax.swing.JLabel();
    lb_thousands = new javax.swing.JLabel();
    lb_decimal = new javax.swing.JLabel();
    lb_multi = new javax.swing.JLabel();
    lb_totals = new javax.swing.JLabel();
    lb_correct = new javax.swing.JLabel();
    lb_wrong = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    bt_ok = new javax.swing.JButton();
    bt_cancel = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

    jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

    jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

    progress.setStringPainted(true);

    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel2.setText("Όνομα βάσης :");

    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel3.setText("Διαχωριστής χιλιάδας :");

    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel4.setText("Διαχωριστής δεκαδικών :");

    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel5.setText("Πλήθος εγγραφών :");

    lb_database.setBackground(new java.awt.Color(255, 255, 255));
    lb_database.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lb_database.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_database.setOpaque(true);

    lb_thousands.setBackground(new java.awt.Color(255, 255, 255));
    lb_thousands.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lb_thousands.setText(" ");
    lb_thousands.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_thousands.setOpaque(true);

    lb_decimal.setBackground(new java.awt.Color(255, 255, 255));
    lb_decimal.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lb_decimal.setText(" ");
    lb_decimal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_decimal.setOpaque(true);

    lb_multi.setBackground(new java.awt.Color(255, 255, 255));
    lb_multi.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lb_multi.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_multi.setOpaque(true);

    lb_totals.setBackground(new java.awt.Color(255, 255, 255));
    lb_totals.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_totals.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_totals.setOpaque(true);

    lb_correct.setBackground(new java.awt.Color(255, 255, 255));
    lb_correct.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_correct.setText("0");
    lb_correct.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_correct.setOpaque(true);

    lb_wrong.setBackground(new java.awt.Color(255, 255, 255));
    lb_wrong.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_wrong.setText("0");
    lb_wrong.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lb_wrong.setOpaque(true);

    jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel6.setText("Διαχ. ή % Πολλαπλασιαστή:");

    jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel7.setText("Εγγραφές που εισήχθησαν:");

    jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel8.setText("Λάθος εγγραφές :");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(progress, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
          .addGroup(jPanel1Layout.createSequentialGroup()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
              .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(lb_database, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(lb_multi, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lb_decimal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lb_thousands, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE))
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(lb_wrong, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lb_correct, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lb_totals, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)))))
        .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel2)
          .addComponent(lb_database, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel3)
          .addComponent(lb_thousands))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel4)
          .addComponent(lb_decimal))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel6)
          .addComponent(lb_multi, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel5)
          .addComponent(lb_totals, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel7)
          .addComponent(lb_correct, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(jLabel8)
          .addComponent(lb_wrong, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(26, 26, 26)
        .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(45, 45, 45))
    );

    jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {lb_correct, lb_database, lb_decimal, lb_multi, lb_thousands, lb_totals, lb_wrong});

    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+2));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("Δημιουργία Βάσης από αρχείο");

    bt_ok.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
    bt_ok.setToolTipText("OK");
    bt_ok.setBorder(null);
    bt_ok.setBorderPainted(false);
    bt_ok.setContentAreaFilled(false);
    bt_ok.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    bt_ok.setFocusable(false);
    bt_ok.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        bt_okActionPerformed(evt);
      }
    });

    bt_cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.png"))); // NOI18N
    bt_cancel.setToolTipText("Κλείσιμο");
    bt_cancel.setBorder(null);
    bt_cancel.setBorderPainted(false);
    bt_cancel.setContentAreaFilled(false);
    bt_cancel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    bt_cancel.setFocusable(false);
    bt_cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        bt_cancelActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
          .addComponent(bt_ok, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(bt_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))))
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(bt_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGap(11, 11, 11)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addComponent(bt_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void bt_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_okActionPerformed
    DataImport d = new DataImport(data, fields);
    Thread t = new Thread(d);
    t.start();
  }//GEN-LAST:event_bt_okActionPerformed

  private void bt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelActionPerformed
    Main.glassPane.deactivate();
    dispose();
  }//GEN-LAST:event_bt_cancelActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton bt_cancel;
  private javax.swing.JButton bt_ok;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JLabel lb_correct;
  private javax.swing.JLabel lb_database;
  private javax.swing.JLabel lb_decimal;
  private javax.swing.JLabel lb_multi;
  private javax.swing.JLabel lb_thousands;
  private javax.swing.JLabel lb_totals;
  private javax.swing.JLabel lb_wrong;
  private javax.swing.JProgressBar progress;
  // End of variables declaration//GEN-END:variables

  class DataImport implements Runnable {

    private final ArrayList<String[]> data;
    private final int[] fields;
    private int total;

    private DataImport(ArrayList<String[]> data, int[] fields) {
      this.data = data;
      this.fields = fields;
      total = data.size();
    }

    public void run() {
      try {
        commit();
      } catch (SQLException ex) {
        Logger.getLogger(Importer.class.getName()).log(Level.SEVERE, null, ex);
      }
    }

    private void commit() throws SQLException {
      long start = System.currentTimeMillis();
      Database.stmt.execute("BEGIN TRANSACTION");
      for (int i = 0; i < data.size(); i++) {
        String[] dataFields = data.get(i);
        String afm = dataFields[fields[ImportConstants.AFM]].trim();
        String amount = dataFields[fields[ImportConstants.AMOUNT]].trim();
        String date = dataFields[fields[ImportConstants.DATE]].trim();
        String type = fields[ImportConstants.TYPE] != ImportConstants.NOT_EXIST ? dataFields[fields[ImportConstants.TYPE]].trim() : ImportConstants.DEFAULT_TYPE;
        String multiplier = fields[ImportConstants.MULTIPLIER] != ImportConstants.NOT_EXIST ? dataFields[fields[ImportConstants.MULTIPLIER]].trim() : "1";

        double dMultiplier = getMultiplier(multiplier);
        double dAmount = getAmount(amount);
        Date dDate = getDate(date);
        int type_id = getTypeId(type, dMultiplier);

        if (dAmount > 0 && dDate != null) {
          Receipt r = new Receipt(0, afm, dAmount,
              dDate, type_id, "", true);
          r.save();
          correct++;
        } else {
          wrong++;
          wrongData.add(dataFields);
        }
        progress.setValue(((i + 1) * 100) / total);
        lb_correct.setText(String.valueOf(correct));
        lb_wrong.setText(String.valueOf(wrong));
      }
      Database.stmt.execute("END TRANSACTION");
      bt_ok.setEnabled(false);
      bt_cancel.setText("Close");
      if(wrong>0){
        File wr = new File(Options.USER_DIR+"wrong.txt");
        try {
          PrintWriter out = Helper.createOutputStream(wr, false);
          for (Iterator<String[]> it = wrongData.iterator(); it.hasNext();) {
            String[] d = it.next();
            out.println(Helper.join(d,"\t"));
          }
          out.close();
           Helper.message("Υπήρξαν " + wrong + " εγγραφές που δεν εισήχθησαν στη βάση\n"
            + "Ένα αρχείο με αυτές τις έγγραφές σώθηκε στη διεύθυνση:\n"
            + wr,
            "Δημιουργία βάσης από αρχείο", JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
          Main.log(Level.SEVERE, null, ex);
        }
       
      }
      imported = true;
    }

    private int getTypeId(String type, double multiplier) throws SQLException {
      int type_id;
      Type t = new Type(0, type, 1, multiplier);
      if (!t.exists()) {
        t.save();
        type_id = Type.getIdByField(Type.TABLE, Type.COLUMN_DESCRIPTION, Type.COLUMN_TYPE_ID, type);
      } else {
        type_id = t.getType_id();
      }
      return type_id;
    }

    private double getAmount(String amount) {
      amount = amount.replaceAll("[^\\d\\.,]", "");
      if (amount.equals("")) {
        return 0.0;
      }
      try {
        return Double.parseDouble(amount);
      } catch (NumberFormatException ex) {
        if (thousandDel == THOUSAND_DEL_COMMA) {
          amount = amount.replaceAll(THOUSAND_DEL[THOUSAND_DEL_COMMA], "");
        } else if (thousandDel == THOUSAND_DEL_STOP) {
          amount = amount.replaceAll("\\" + THOUSAND_DEL[THOUSAND_DEL_STOP], "");
        }
        amount = amount.replaceAll(DECIMAL_DEL[DECIMAL_DEL_COMMA], DECIMAL_DEL[DECIMAL_DEL_STOP]);
        try {
          return Double.parseDouble(amount);
        } catch (Exception ex1) {
          return 0.0;
        }
      }
    }

    private Date getDate(String date) {
      if(date.equals("")){
        return null;
      }
      String[] f = date.split("[/-]");
      if(f.length!=3){
        return null;
      }
      if (f[2].length() == 2) {
        date = f[0] + "/" + f[1] + "/20" + f[2];
      }
      return Helper.convertStringToDate(date);
    }

    private double getMultiplier(String multiplier) {
      try {
        if (multiDecimalDel == MULTI_DEC_PERC) {
          return Double.parseDouble(multiplier) / 100;
        } else if (multiDecimalDel == MULTI_DEC_COMMA) {
          multiplier = multiplier.replaceAll(MULTI_DEC_DEL[MULTI_DEC_COMMA], MULTI_DEC_DEL[MULTI_DEC_STOP]);
          return Double.parseDouble(multiplier);
        } else {
          return Double.parseDouble(multiplier);
        }
      } catch (NumberFormatException ex) {
        return 1.0;
      }
    }
  }
}
